home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
GMISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
22KB
|
925 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
/* gmisc - translation of setl misc.c */
#define GEN
#include "hdr.h"
#include "vars.h"
#include "segment.h"
#include "gvars.h"
#include "ops.h"
#include "slot.h"
#include "dbxp.h"
#include "exprp.h"
#include "setp.h"
#include "genp.h"
#include "gmainp.h"
#include "segmentp.h"
#include "arithp.h"
#include "libp.h"
#include "gutilp.h"
#include "initp.h"
#include "miscp.h"
#include "smiscp.h"
#include "gmiscp.h"
static void relay_set_add(Symbol);
static int in_slot_map(Tuple, Symbol);
static Tuple labelmap_def(Symbol);
extern Segment CODE_SEGMENT, DATA_SEGMENT, DATA_SEGMENT_MAIN;
unsigned int subprog_patch_get(Symbol sym) /*;subprog_patch_get*/
{
int i, n;
/* search tuple SUBPROG_PATCH for symbol, return*/
n = tup_size(SUBPROG_PATCH);
for (i = 1; i <= n; i += 2) {
if ((Symbol) SUBPROG_PATCH[i] == sym)
return (unsigned int) SUBPROG_PATCH[i+1];
}
return 0; /* is this right or should there be error return?*/
}
void subprog_patch_put(Symbol sym, int off) /*;subprog_patch_put*/
{
int i, n;
n = tup_size(SUBPROG_PATCH);
for (i = 1; i <= n; i += 2) {
if ((Symbol) SUBPROG_PATCH[i] == sym ) {
SUBPROG_PATCH[i+1] = (char *) off;
return;
}
}
/* here if need new element */
SUBPROG_PATCH = tup_exp(SUBPROG_PATCH, n+2);
SUBPROG_PATCH[n+1] = (char *) sym;
SUBPROG_PATCH[n+2] = (char *) off;
/* SUBPROG_PATCH is map as tuple: domain elements are symbols, vales
* are integers
*/
}
void subprog_patch_undef(Symbol sym) /*;subprog_patch_undef*/
{
int i, n, j;
n = tup_size(SUBPROG_PATCH);
for (i = 1; i <= n; i += 2) {
if ((Symbol) SUBPROG_PATCH[i] == sym) {
for (j = i+2; j <= n; j++)
SUBPROG_PATCH[j-2] = SUBPROG_PATCH[j];
SUBPROG_PATCH[0] = (char *) n-2; /* adjust size */
break;
}
}
}
/* Miscelleanous utilities on types */
Symbol base_type(Symbol name) /*;base_type*/
{
/*
* The base-type of a type-mark is itself, unless the type-mark denotes
* a subtype.
*/
while (NATURE(name) == na_subtype && TYPE_OF(name) != name)
name = TYPE_OF(name);
return name;
}
int is_discrete_type(Symbol name) /*;is_discrete_type*/
{
Symbol btype;
if (cdebug2 > 3)
TO_ERRFILE("AT PROC : is_discrete_type") ;
if (TYPE_OF(name) != (Symbol)0) btype = root_type(name);
else return FALSE;
if (btype == symbol_integer
|| btype == symbol_universal_integer
|| btype == symbol_discrete_type
|| btype == symbol_any) return TRUE;
if (NATURE(btype) == na_enum ) return TRUE;
return FALSE;
}
int is_unconstrained(Symbol typ) /*;is_unconstrained*/
{
Symbol parent_type;
switch( NATURE(typ)) {
case(na_array):
return TRUE;
case(na_record):
return has_discriminant(typ);
case(na_type):
parent_type = TYPE_OF(typ);
if (parent_type == typ)
return FALSE;
else
return is_unconstrained(parent_type);
default:
return FALSE;
}
}
int not_included(Symbol small_type, Symbol large_type) /*;not_included*/
{
/*
* Checks if the bounds of small_type are (statically) out of those of
* large_type.
*/
Node small_low_def, small_high_def, large_low_def, large_high_def;
Tuple tup;
Const small_low, small_high, large_low, large_high;
if (large_type == base_type(small_type))
return FALSE; /* even if not static in that case */
tup = SIGNATURE(small_type);
small_low_def = (Node) tup[2];
small_high_def = (Node) tup[3];
tup = SIGNATURE(large_type);
large_low_def = (Node) tup[2];
large_high_def = (Node) tup[3];
small_low = get_ivalue(small_low_def);
small_high = get_ivalue(small_high_def);
large_low = get_ivalue(large_low_def);
large_high = get_ivalue(large_high_def);
if (small_low->const_kind == CONST_OM
|| small_high->const_kind == CONST_OM
|| large_low->const_kind == CONST_OM
|| large_high->const_kind == CONST_OM) {
return TRUE;
}
else if (is_fixed_type(large_type) || is_float_type(large_type)) {
return const_lt(small_low, small_high)
&& (const_lt(small_low, large_low)
|| const_gt(small_high, large_high));
}
else {
return const_lt(small_low , small_high)
&& (const_lt(small_low , large_low)
|| const_gt(small_high , large_high));
}
}
#ifndef BINDER
void optional_qual(Symbol source_type, Symbol target_type) /*;optional_qual*/
{
Symbol source_obj_type, target_obj_type;
/* Generates a qual if necessary. The value is already on top of stack. */
if (target_type == base_type(source_type))
; /* qual never necessary here */
else if (is_access_type(target_type)) {
source_obj_type = (Symbol) designated_type(source_type);
target_obj_type = (Symbol) designated_type(target_type);
if (target_obj_type != source_obj_type
&& target_obj_type != base_type(source_obj_type)) {
if (is_array_type(target_obj_type)) {
gen_access_qual(as_qual_index, target_obj_type);
}
else if (is_record_type(target_obj_type)) {
gen_access_qual(as_qual_discr, target_obj_type);
}
else { /* simple type */
; /* No need to qual range */
}
}
}
else if (is_simple_type(target_type) &&
not_included(source_type, target_type)) {
gen_s(I_QUAL_RANGE, target_type);
}
}
#endif
int kind_of(Symbol type_name) /*;kind_of*/
{
/*
* Determines the memory unit addressing mode for the given type.
* NOTE: This procedure is the point where the code generator bombs whenever
* there is something wrong with a type declaration....
*/
int nat, tsiz;
type_name = root_type(type_name);
#ifdef TRACE
if (debug_flag)
gen_trace_symbol("KIND_OF", type_name);
#endif
nat = NATURE(type_name);
if (nat == na_array) {
return mu_dble;
}
else if (nat == na_record || nat == na_access) {
return mu_addr;
}
else if (nat == na_package) {
return mu_byte;
}
else if (nat == na_enum) {
return mu_word;
}
else {
tsiz = TYPE_KIND(type_name);
if (tsiz == TK_BYTE) {
return mu_byte;
}
else if (tsiz == TK_WORD) {
return mu_word;
}
else if (tsiz == TK_ADDR){
return mu_addr;
}
else if (tsiz == TK_LONG) {
return mu_long;
}
else if (tsiz == TK_XLNG) {
return mu_xlng;
}
else {
compiler_error_s("Kind_of returning omega. Type name is ",
type_name);
return mu_word; /* mu_word bogus value so can proceed */
}
}
}
int length_of(Symbol type_name) /*;length_of*/
{
/* gives the number of item in the type, assumed to be a discrete type */
Node low, high;
Tuple tup;
Const low_const, high_const;
int bs, bi;
tup = SIGNATURE(type_name);
low = (Node) tup[2];
high = (Node) tup[3];
low_const = get_ivalue(low);
high_const = get_ivalue(high);
if (low_const->const_kind != CONST_OM
&& high_const->const_kind != CONST_OM) {
/* return get_ivalue_int(high)-get_ivalue_int(low)+1; */
bi = get_ivalue_int (low);
bs = get_ivalue_int (high);
if (bi > bs)
return 0;
else
return bs - bi + 1;
}
else {
return -1;
}
}
/* On symbol table */
void new_symbol(Symbol new_name, int new_nature, Symbol new_type,
Tuple new_signature, Symbol new_alias) /*;new_symbol*/
{
NATURE(new_name) = new_nature;
TYPE_OF(new_name) = new_type;
SIGNATURE(new_name) = new_signature;
ALIAS(new_name) = new_alias;
}
/* On addresses */
void reference_of(Symbol name) /*;reference_of*/
{
/* The C version returns result in two globals; ref_seg?? and ref_off ?? */
int lrmval;
#ifdef SKIP
REFERENCE_OFFSET = 0;
REFERENCE_SEGMENT = 0; /* for initial checkout*/
return;
#endif
if (tup_mem((char *) name , PARAMETER_SET)) {
if (!tup_mem((char *) PC(), CODE_PATCH_SET)) {
CODE_PATCH_SET = tup_with(CODE_PATCH_SET, (char *)PC());
}
/* Parameters always referenced */
/* from assemble, peep-hole OK. */
REFERENCE_SEGMENT = 0;
REFERENCE_OFFSET = local_reference_map_get(name);
}
else if (local_reference_map_defined(name)) {
REFERENCE_SEGMENT = 0;
REFERENCE_OFFSET = local_reference_map_get(name);
}
else if (S_SEGMENT(name) != -1) {
REFERENCE_SEGMENT = S_SEGMENT(name);
REFERENCE_OFFSET = S_OFFSET(name);
}
else {
lrmval =